# 角色-权限绑定接口
from flask import request, jsonify
from flask_jwt_extended import jwt_required
from backend.api.user_api import admin_required
from backend.services.role_permission_service import get_role_permissions, set_role_permissions

@jwt_required()
@admin_required
def list_role_permissions(role_id):
    perms = get_role_permissions(role_id)
    return jsonify({'success': True, 'data': perms})

@jwt_required()
@admin_required
def update_role_permissions(role_id):
    data = request.get_json(force=True, silent=True)
    permission_ids = data.get('permission_ids', [])
    result = set_role_permissions(role_id, permission_ids)
    return jsonify(result)
